<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="addccc">
          <el-button
            type="primary"
            @click="newest(1)"
            icon="el-icon-circle-plus-outline"
            >新增授权</el-button
          >
        </div>
      </el-col>
      <el-col :span="24">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column type="expand">
            <template #default="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="产品销售:">
                  <span>{{ props.row.name1 }}</span>
                </el-form-item>
                <el-form-item label="合作协议:">
                  <el-button type="warning" size="small">下载</el-button>
                </el-form-item>
                <el-form-item label="证书复印件:">
                  <el-button type="warning" size="small">下载</el-button>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="经销商" prop="name"> </el-table-column>
          <el-table-column label="编号" prop="desc"> </el-table-column>
          <el-table-column label="授权时间" prop="desc1"> </el-table-column>
          <el-table-column label="到期日期" prop="desc2"> </el-table-column>
          <el-table-column label="折扣" prop="desc3"> </el-table-column>
          <el-table-column label="证书编号" prop="desc4"> </el-table-column>
          <el-table-column label="状态" prop="desc4"> </el-table-column>
          <el-table-column label="备注" prop="desc4"> </el-table-column>

          <el-table-column label="操作" width="240" align="center">
            <template #default="scope">
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
                >下载</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog
      :title="single"
      v-model="plassets"
      width="45%"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :inline="true" :model="form" label-width="100px">
        <el-form-item label="经销商">
          <el-input v-model="form.dealers" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="编号">
          <el-input v-model="form.serial" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="授权时间">
          <el-date-picker
            style="width: 300px"
            v-model="form.authorization"
            type="date"
            placeholder="选择日期"
            format="YYYY 年 MM 月 DD 日"
          >
            >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到期时间">
          <el-date-picker
            style="width: 300px"
            v-model="form.risultato"
            type="date"
            placeholder="选择日期"
            format="YYYY 年 MM 月 DD 日"
          >
            >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="折扣">
          <el-input
            v-model="form.discount"
            type="number"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="合作协议">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="cooperation"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <template #tip>
              <div class="el-upload__tip">
                只能上传 jpg/png 文件，且不超过 500kb
              </div>
            </template>
          </el-upload>
        </el-form-item>
        <el-form-item label="证书编号">
          <el-input v-model="form.certificate" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="证书复印件" style="width: 300px">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="cooperation"
          >
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            style="width: 300px"
            v-model="form.state"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in foreach"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品销售">
          <el-input v-model="form.sales" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            :rows="2"
            style="width: 300px"
            placeholder="请输入内容"
            v-model="form.newnotes"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="plassets = false">取 消</el-button>
          <el-button type="primary" v-if="under == 1" @click="determine()"
            >确 定</el-button
          >
          <el-button @click="hardware()" v-else type="primary"
            >编辑 确 定</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cooperation: [],
      plassets: false,
      under: 1,
      single: "新增授权信息",
      form: {
        dealers: "",
        serial: "",
        authorization: "",
        risultato: "",
        discount: "",
        certificate: "",
        state: "",
        sales: "",
        newnotes: "",
      },
      foreach: [],
      tableData: [
        {
          name1: "张三",
          name: "杭州xxxxxxxxx",
          category: "xxxxxx",
          desc: "xxxxxxx",
          desc1: "USG",
          desc2: "10000",
          desc3: "1",
          desc4: "xxxxx",
          desc5: "1",
          address: "xxxx",
          shop: "xxxxx",
          shopId: "xxxxxx",
        },
      ],
    };
  },
  methods: {
    newest(index) {
      this.under = index;
      this.single = "新增授权信息";
      this.plassets = true;
    },
    //合作协议
    handleRemove(file, cooperation) {
      console.log(file, cooperation);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, cooperation) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + cooperation.length
        } 个文件`
      );
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>

<style >
.addccc {
  margin-bottom: 20px;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 100px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 100%;
}
</style>